using System;
using Common.Commands.TrackLogCommands;
using Common.Views;
using Core.Domain.Model;
using NUnit.Framework;
using Sanelib.Common.Extensions;
using Sanelib.Common.Helpers;
using Sanelib.DataView;

namespace IntegrationTests.Processors
{
    public class TrackLogProcessorTester : IntegrationTestBase
    {
        [Test, Explicit]
        public void ShouldAddTrackLog()
        {
            var member = GetSiteUser();
            Persist(member);

            var command = new AddTrackLog
            {
                Id = GuidComb.New(),
                Name = member.Name,
                TagId = member.TagId,
                DetectedOn = DateTime.Now.AddDays(+5)
            };

            ProcessCommand(command);

            var repo = GetInstance<IViewRepository<TrackLogView>>();
            var trackLog = repo.GetByKey(Property.Of<TrackLogView>(x => x.Id), command.Id);

            Assert.AreEqual(command.DetectedOn, trackLog.DetectedOn);
        }

        [Test, Explicit]
        public void ShouldUpdateTrackLog()
        {
            var member = GetSiteUser();
            
            var trackLog = new TrackLog
            {
                Id = GuidComb.New(),
                Name = member.Name,                
                ImageData = ImageUtility.NoImageData,
                Code = member.Code,
                DetectedOn = DateTime.Now.AddDays(+5),
                Description = "Old Description",
                CreatedBy = member.Id                
            };

            Persist(member, trackLog);

            var command = new UpdateTrackLog
            {
                Id = trackLog.Id,
                ImageData = ImageUtility.NoImageData,
                DetectedOn = DateTime.Now.AddDays(+3),
                Description = "New Description",                
            };

            ProcessCommand(command);

            var repo = GetInstance<IViewRepository<TrackLogView>>();
            var trackLogView = repo.GetByKey(Property.Of<TrackLogView>(x => x.Id), command.Id);

            Assert.AreNotEqual(trackLog.DetectedOn, trackLogView.DetectedOn);
            Assert.AreNotEqual(trackLog.Description, trackLogView.Description);
        }

        [Test, Explicit]
        public void ShouldDeleteTrackLog()
        {
            var member = GetSiteUser();

            var trackLog = new TrackLog
            {
                Id = GuidComb.New(),
                Name = member.Name,
                ImageData = ImageUtility.NoImageData,
                Code = member.Code,
                DetectedOn = DateTime.Now.AddDays(+5),
                Description = "Old Description",
                CreatedBy = member.Id
            };

            Persist(member, trackLog);

            var command = new DeleteTrackLog(trackLog.Id);

            ProcessCommand(command);

            var repo = GetInstance<IViewRepository<TrackLogView>>();
            var trackLogView = repo.GetByKey(Property.Of<TrackLogView>(x => x.Id), command.Id);

            Assert.IsNull(trackLogView);
        }
    }
}